// pages/under-door/list/index.js
import api from '../../../api/index';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading: false,
    isComplete: false,
    list: [],
    formData: {
      stateList: [0], //待调查0 调查中 1 已调查  3
      yid: 0,
      pageNo: 1,
      pageSize: 10,
      keyword: '', //搜索
    },
    state: 0, //调查状态
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  //搜索
  search() {
    this.setData({
      [`formData.pageNo`]: 1,
      list: [],
      isLoading: false,
      isComplete: false,
    })
    this.getList();
  },
  //关键词输入
  bindinput(e) {
    let value = e.detail.value;
    this.setData({
      [`formData.keyword`]: value
    })
  },
  //去详情
  detail(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id;
    let isRealSurveer=e.currentTarget.dataset.isrealsurveyer;
    if (this.data.state == 0) {
      //带调查详情
      wx.navigateTo({
        url: `/pages/under-door/to-investigate/index?id=${id}`,
      })

    } else if (this.data.state == 1) {
      //调查中
      wx.navigateTo({
        url: `/pages/under-door/orientation-check-in/index?id=${id}`,
      })
    } else {
      //已调查
      wx.navigateTo({
        url: `/pages/under-door/surveyed/index?id=${id}&isRealSurveer=${isRealSurveer}`,
      })

    }
  },
  //切换状态
  onChangeNav(e) {
    let type = e.currentTarget.dataset.type;
    this.setData({
      state: type,
      [`formData.stateList`]: [+type],
      [`formData.pageNo`]: 1,
      isLoading: false,
      isComplete: false,
      list: [],
      [`formData.keyword`]: '',
    })
    this.getList();
  },
  //获取列表
  getList() {
    api.getTaskPage(this.data.formData).then(res => {
      this.setData({
        isLoading: false,
        isComplete: !res.data.data.records.length,
        list: this.data.list.concat(res.data.data.records),
        [`formData.pageNo`]: ++this.data.formData.pageNo
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      isLoading: false,
      isComplete: false,
      list: [],
      [`formData.pageNo`]: 1
    })
    this.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    !this.data.isComplete && !this.data.isLoading && this.getList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})